{include file="public/layout" /}
<body class="laytp-container">
<div class="layui-card" id="search-form">
    <div class="layui-card-body">
		<form class="layui-form layui-row layui-col-space16 layui-search-admin">
		<div class="layui-inline layuiadmin-input-useradmin">
			<label class="layui-form-label">姓名</label>
			<div class="layui-input-inline">
				<input type="text" name="realname" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">状态</label>
			<div class="layui-input-inline">
				<select name="status">
					<option value="">全部</option>
					<option value="1">已开启</option>
					<option value="0">已关闭</option>
				</select>
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label"></label>
			<button class="layui-btn" lay-submit lay-filter="demo-table-search">搜索</button>
			<button type="reset" class="layui-btn layui-btn-primary">清空</button>
		</div>
	</form>
	</div>
</div>
<div class="layui-card">
	<div class="layui-card-body">
		<table id="tabledata" lay-filter="tabledata"></table>
	</div>
</div>
<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-sm" onclick="add()">
			添加
		</button>
		<button class="layui-btn layui-btn-sm" onclick="reload()">
			刷新数据
		</button>
		<button class="layui-btn layui-btn-sm" onclick="del()">
			批量删除
		</button>
		<button class="layui-btn layui-btn-sm" data-form-export="{:url('excel')}">
			导出数据
		</button>

	</div>
</script>
	<script>
		var tableIns
		var datawhere = {};
		layui.use(function() {
			var table = layui.table;
			//数据表
			tableIns = table.render({
				elem: '#tabledata'
				, url: "{$Request.url}" //数据接口
				, page: true, //开启分页
				toolbar: '#toolbarDemo',
				defaultToolbar: ['filter'],
				cols: [[ //表头
					{type: "checkbox"},
					{field: 'id', title: 'ID', sort: true, width: 80},
					{field: 'realname', title: '配送员姓名'},
					{field: 'tel', title: '配送员电话'},
					{
						field: 'nickname', title: '头像昵称', templet: function (d) {
							if (d.nickname) {
								return '<img src="' + d.headimg + '" style="width:40px;height:40px"/> ' + d.nickname
							}
							return '';
						}
					},
					{
						field: 'pszCount', title: '配送中/已完成', templet: function (d) {
							return d.pszCount + ' / ' + d.ywcCount
						}
					},
					{
						field: 'sort', title: '创建时间', templet: function (d) {
							return date('Y-m-d H:i', d.createtime)
						}
					},
					{
						field: 'status', title: '状态', templet: function (d) {
							if (d.status == 0) {
								return '<span style="color:red">已关闭</span>';
							} else if (d.status == 1) {
								return '<span style="color:green">已开启</span>';
							}
						}
					},
					{
						field: 'right', title: '操作', templet: function (d) {
							var html = '';
							html += '<button class="layui-btn layui-btn-xs"  onclick="openmax(\'{:url('edit')}/id/' + d.id + '\')">编辑</button>';
							html += '<button class="layui-btn layui-btn-xs" onclick="datadel(' + d.id + ')">删除</button>';
							html += '<button class="layui-btn layui-btn-xs" onclick="openmax(\'{:url('PeisongOrder / index')}/isopen/1/psid/' + d.id + '\')">查看配送记录</button>';
							return html;
						}
					}
				]]
			});
		})
	//排序
	layui.table.on('sort(tabledata)', function(obj){
		datawhere.field = obj.field;
		datawhere.order = obj.type;
		tableIns.reload({
			initSort: obj,
			where: datawhere
		});
	});
	//检索
	layui.form.on('submit(LAY-app-forumreply-search)', function(obj){
		var field = obj.field
		var olddatawhere = datawhere
		datawhere = field
		datawhere.field = olddatawhere.field
		datawhere.order = olddatawhere.order
		tableIns.reload({
			where: datawhere,
			page: {curr: 1}
		});
	})
		function add(){
			layer.open({
				title: '添加',
				type: 2,
				shadeClose: true,
				area: ['100%','100%'],
				scrollbar:false,
				content: '{:url("edit")}'
			});
		}
		function edit(id){
			var url = '/admin/PeisongUser/edit/id/'+id
			layer.open({
				title: '添加',
				type: 2,
				shadeClose: true,
				area: ['100%','100%'],
				scrollbar:false,
				content: url
			});
		}
	function setticheng(){
		var html = '';
		html+='	<div class="layui-form-item" style="margin-top:40px;margin-right:20px;">';
		html+='		<label class="layui-form-label" style="width:80px">每单提成</label>';
		html+='		<div class="layui-input-inline" style="width:180px">';
		html+='			<input type="text" id="ticheng" class="layui-input" value="{$psset.ticheng}"/>';
		html+='		</div>';
		html+='		<div class="layui-form-mid">元</div>';
		html+='	</div>';
		var refundLayer = layer.open({type:1,area:['500px','250px'],title:false,content:html,shadeClose:true,btn: ['确定', '取消'],
			yes:function(){
				var index = layer.load();
				$.post("{:url('setticheng')}",{ticheng:$('#ticheng').val()},function(res){
					layer.close(index);
					dialog(res.msg,res.status,true);
				})
			}
		})
	}
	//删除
	function datadel(id){
		var ids = [];
		if(id==0){
			var checkStatus = table.checkStatus('tabledata')
			var checkData = checkStatus.data; //得到选中的数据
			if(checkData.length === 0){
				 return layer.msg('请选择数据');
			}
			for(var i=0;i<checkData.length;i++){
				ids.push(checkData[i]['id']);
			}
		}else{
			ids.push(id);
		}
		layer.confirm('确定要删除吗？删除后无法恢复！',{icon: 7, title:'操作确认'}, function(index){
			//do something
			layer.close(index);
			var index = layer.load();
			$.post("{:url('del')}",{ids:ids},function(data){
				layer.close(index);
				dialog(data.msg,data.status);
				tableIns.reload()
			})
		});
	}
	//上下架
	function setst(id,st){
		var ids = [];
		if(id==0){
			var checkStatus = table.checkStatus('tabledata')
			var checkData = checkStatus.data; //得到选中的数据
			if(checkData.length === 0){
				 return layer.msg('请选择数据');
			}
			for(var i=0;i<checkData.length;i++){
				ids.push(checkData[i]['id']);
			}
		}else{
			ids.push(id);
		}
		layer.confirm('确定要'+(st==0?'关闭':'开启')+'吗?',{icon: 7, title:'操作确认'}, function(index){
			//do something
			layer.close(index);
			var index = layer.load();
			$.post("{:url('setst')}",{ids:ids,st:st},function(data){
				layer.close(index);
				dialog(data.msg,data.status);
				tableIns.reload()
			})
		});
	}
	function showqr(id){
		var pagepath = 'activity/peisong/orderlist';
		viewLink(pagepath);
	}
	</script>
</body>
</html>